<script>
    function sommeQuantite(id, unite, vergile) {
        $('#stock_quantite_somme_' + id).html((parseFloat($('#stock_quantite_noir_' + id).val()) + parseFloat($('#stock_quantite_' + id).val())).toFixed(vergile) + ' ' + unite);
    }
    </script>
    <div class="giveHeight"> 
        <table class="responsive dynamicTable display table table-bordered dataTable">

            <thead> 
                <tr>
                                        {{ knp_pagination_sortable(pagination, 'Réference', 'a.reference') }}
                                         {{ knp_pagination_sortable(pagination, 'Désignation', 'a.designation') }}
                        <th>Quantite</th>
                    {% if app.session.get('stock') == code %}
                            <td>Quantite Noir</td>
                            <td>Somme quantite</td>
                {% endif %}
                            <th>Quantite Min</th>
                        </tr>
                    </thead>
{# table body #}
{% for stock in pagination %}
                    <tr {% if loop.index is odd %}class="color"{% endif %}>
                        <td>{{ stock.reference }}</td>
                        <td>{{ stock.designation }}</td>
                        <td><input type="text" id="stock_quantite_{{stock.id}}" />{{stock.code}}</td>
                    <script>
                        var i = stockSearch(stocks, '{{stock.id}}');

                        $('#stock_quantite_{{stock.id}}').spinner({
                            step: 1,
                            places: {{stock.chiffre_virgule}},
                            max: 99999999999999,
                            showOn: 'both'
                        });

                        if (i == -1) {
                            var stock = eval('(' + "{'id':'{{stock.id}}','quantite':'{{stock.quantite_blanc|number_format(stock.chiffre_virgule)}}','quantite_noir':'{{stock.quantite_noir|number_format(stock.chiffre_virgule)}}','quantite_min':'{{stock.quantite_min|number_format(stock.chiffre_virgule)}}','new':'1'}" + ')');
                            stocks[stocks.length] = stock
                            $('#stock_quantite_{{stock.id}}').val('{{stock.quantite_blanc|number_format(stock.chiffre_virgule)}}')
                            $('#stock_quantite_min_{{stock.id}}').val('{{stock.quantite_min|number_format(stock.chiffre_virgule)}}')
                        } else {
                            $('#stock_quantite_{{stock.id}}').val(stocks[i].quantite)
                            $('#stock_quantite_min_{{stock.id}}').val(stocks[i].quantite_min)
                        }
                        $('#stock_quantite_{{stock.id}}').change(function() {
                            sommeQuantite('{{stock.id}}', '{{stock.code}}',{{stock.chiffre_virgule}});
                            stocks[stockSearch(stocks, '{{stock.id}}')].quantite = $('#stock_quantite_{{stock.id}}').val()
                            stocks[stockSearch(stocks, '{{stock.id}}')].new = 0;
                        })


                        </script>
                {% if app.session.get('stock') == code %}
                        <td><input type="text" id="stock_quantite_noir_{{stock.id}}" /> {{stock.code}}</td>
                        <td id="stock_quantite_somme_{{stock.id}}"></td>
                        <script>
                            $('#stock_quantite_noir_{{stock.id}}').spinner({
                                step: 1,
                                places: {{stock.chiffre_virgule}},
                                max: 99999999999999,
                                showOn: 'both'
                            });

                            $('#stock_quantite_noir_{{stock.id}}').change(function() {
                                sommeQuantite('{{stock.id}}', '{{stock.code}}',{{stock.chiffre_virgule}})
                                stocks[stockSearch(stocks, '{{stock.id}}')].quantite_noir = $('#stock_quantite_noir_{{stock.id}}').val()
                                stocks[stockSearch(stocks, '{{stock.id}}')].new = 0;
                            })
                            if (i == -1) {
                                    $('#stock_quantite_noir_{{stock.id}}').val('{{stock.quantite_noir|number_format(stock.chiffre_virgule)}}')
                                } else {
                                    $('#stock_quantite_noir_{{stock.id}}').val(stocks[i].quantite_noir)
                                }
                            sommeQuantite('{{stock.id}}', '{{stock.code}}',{{stock.chiffre_virgule}})

                            </script>
                    {% endif %}
                            <td><input type="text" id="stock_quantite_min_{{stock.id}}" /> {{stock.code}}</td>

                            <script>
                                $('#stock_quantite_min_{{stock.id}}').spinner({
                                    step: 1,
                                    places: {{stock.chiffre_virgule}},
                                    max: 99999999999999,
                                    showOn: 'both'
                                });
                                if (i == -1) {
                                    $('#stock_quantite_min_{{stock.id}}').val('{{stock.quantite_min|number_format(stock.chiffre_virgule)}}')
                                } else {
                                    $('#stock_quantite_min_{{stock.id}}').val(stocks[i].quantite_min)
                                }
                                $('#stock_quantite_min_{{stock.id}}').change(function() {
                                    sommeQuantite('{{stock.id}}', '{{stock.code}}',{{stock.chiffre_virgule}});
                                    stocks[stockSearch(stocks, '{{stock.id}}')].quantite_min = $('#stock_quantite_min_{{stock.id}}').val()
                                    stocks[stockSearch(stocks, '{{stock.id}}')].new = 0;
                                })
                                </script>
                                </tr>
{% endfor %}
                                </table>
                            </div>
                            <div id="DataTables_Table_0_info" class="dataTables_info">Affichage de {{ (pagination.getCurrentPageNumber -1)*pagination.getItemNumberPerPage + 1}} à {{ (pagination.getCurrentPageNumber -1)*pagination.getItemNumberPerPage + pagination.getItemNumberPerPage}} de {{ pagination.getTotalItemCount }} Articles</div>
{# display navigation #}
                            <div id="DataTables_Table_0_paginate" class="dataTables_paginate paging_full_numbers">
    {{ knp_pagination_render(pagination) }}
                                </div>


